<template>
  <div id="supplierAudit">
    <el-form>
      <br>
      <el-form-item label="公司名称">
        <el-input v-model="searchObj.supplierName" placeholder="账号"></el-input>
      </el-form-item>
      <br>
      <br>
      <el-form-item>
        <el-button type="primary" @click="search">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
        :data="tableData"
        style="width: 100%">
      <el-table-column
          label="id"
          width="180"
          prop="id">
        <template slot-scope="scope">
          <router-link :to="{path:'/supplierById',query:{index:scope.row.id}}">
            {{scope.row.id}}
          </router-link>
        </template>
      </el-table-column>
      <el-table-column
          label="公司名称"
          width="180" prop="supplierName">

      </el-table-column>
      <el-table-column
          prop="userSupplierTag"
          label="审核状态">
        <template slot-scope="scope">
          {{ scope.row.userSupplierTag == "0" ? "等待审核" : (scope.row.userSupplierTag == "S001-2" ? "审核未通过" : "审核通过") }}

        </template>
      </el-table-column>
      <el-table-column
          prop="auitOpinion"
          label="审核意见">
      </el-table-column>
      <el-table-column
          prop="supplierIamge"
          label="营业执照图片">
        <template slot-scope="scope">
          <img :src="scope.row.supplierIamge" width="30%">
        </template>
      </el-table-column>

      <el-table-column
          prop="address"
          label="地址">
      </el-table-column>
      <el-table-column
          prop="supplierNumber"
          label="联系电话">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="warning" @click="showAddDialog(scope.$index, scope.row)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>


    <!--添加对话框-->
    <el-dialog title="供应商审核" :visible.sync="addFormVisible" width="60%">
      <el-form :inline="true" :model="form" class="demo-from-inline" label-width="100px">
        <input type="hidden" name="id" :value="form.id"></input>
        <el-form-item label="公司名称">
          <el-input type="text" :value="form.supplierName"></el-input>
        </el-form-item>
        <br>
        <el-form-item label="联系电话">
          <el-input type="text" :value="form.supplierNumber"></el-input>
        </el-form-item>
        <br>
        <el-form-item label="审核意见">
          <el-input type="text" :value="form.auitOpinion"></el-input>
        </el-form-item>
        <br>
        <el-form-item label="地址" width="200px">
          <el-input type="text" :value="form.address"  width="200px"></el-input>
        </el-form-item>
        <br>
        <el-form-item label="审核人">
          <el-input type="text" :value="form.checker"></el-input>
        </el-form-item>
        <br>
        <el-form-item label="审核时间">
          <el-input type="text" :value="form.checkTime" readonly></el-input>
        </el-form-item>
        <br>
        <el-form-item label="营业执照">
          <img :src="form.supplierIamge" width="10%">
        </el-form-item>

      </el-form>
      <div slot="footer">
        <el-button @click="addFormVisible = false">取 消</el-button>
        <el-button type="success" @click="not">不 通 过</el-button>
        <el-button type="primary" @click="uptsainv">通 过</el-button>
      </div>


    </el-dialog>

    <!-- //分页功能 -->
    <div class="block">

      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNo"
          :page-sizes="pageSizeList"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>

  </div>
</template>

<script>
export default {
  created() {
    this.getComments()
  },
  methods: {

    handleSizeChange(val) {
      this.pageSize = val
      this.getComments()
    },
    handleCurrentChange(val) {
      this.pageNo = val
      this.getComments()
    },
    search() {
      this.pageNo = 1,
          this.getComments()
    },
    async getComments() {
      const {data: res} = await this.$http.post(`/supplier/selAudit/${this.pageNo}/${this.pageSize}`, this.searchObj)
      this.tableData = res.rows
      this.total = res.total
    },
    showAddDialog(index, row) {
      this.addFormVisible = true

      this.form = row

    },
    async uptsainv() {
      const data = await this.$http.post(`/supplier/updateOk`, this.form)
      if (data.status == 200) {
        this.addFormVisible = false
        this.$message("修改成功")
        this.getComments()
      }
    },
    async not() {
      const data = await this.$http.post(`/supplier/updateNot`, this.form)
      if (data.status == 200) {
        this.addFormVisible = false
        this.$message("审核不通过")
        this.getComments()
      }
    }
  },
  data() {
    return {
      tableData: [],// 添加对话框的显示
      addFormVisible: false,
      pageNo: 1,
      pageSizeList: [2, 5, 10, 20],
      total: 0,
      pageSize: 2,
      searchObj: {},
      form: {}
    }
  }
}
</script>

<style scoped>

</style>